import request from '@/utils/request'

/**
 * @returns {*}
 */
export function reportingProcess(params) {
  return request({
    url: '/cloud/jcce/v1.0/kt2/reportingProcess',
    method: 'post',
    data: params
  })
}

import bpmnModal from '../bpmnModal.vue'
import { newxx } from './newxx' // 流程图初始配置，编辑的话只需要相同格式的文件替换即可
export default {
  name: 'bpmn',
  components: {
    bpmnModal
  },
  data() {
    return {
      xmlStrWithCustom:'',// 解析用户上传的xml
      isLoading: false,
      flag: false,
      form:{
        name: '',
      },
      uploadDialogVisible: false,
      customActivity: false,// 自定义工作流按上传按钮
      params: {
        reportJson: {},
        cpuJson: {},
        processMap: {},
        processInfo: '',
        cpu: 8,
        mem: 16,
        storage: 100
      },
      radio: '视频业务工作流',
      xmlStrWithValues: '',
      process: {
        process_one: {
          task: {
            vi_1: '3230',
            vi_2: '3230',
            vi_3: '3230',
            vi_4: '3230',
            vi_5: '16',
            vi_6: '24',
            vi_7: '40',
            vi_8: '76',
            vi_9: '133',
            vi_10: '267',
            vi_11: '270',
            vi_12: '408',
            vi_13: '190',
            vi_14: '432',
            vi_15: '190'
          },
          node: {
            nd_0: '285',
            nd_1: '37',
            nd_2: '62',
            nd_3: '46',
            nd_4: '151',
            nd_5: '140',
            nd_6: '100',
            nd_7: '158',
            nd_8: '240',
            nd_9: '324',
            nd_10: '87',
            nd_11: '478',
            nd_12: '419'
          }
        },
        process_two: {
          task: {
            fat_0: '270',
            fat_1: '323',
            fat_2: '743784',
            fat_3: '743784',
            fat_4: '743784',
            fat_5: '226514',
            fat_6: '226514',
            fat_7: '226514',
            fat_8: '107',
            fat_9: '6955',
            fat_10: '6955',
            fat_11: '971',
            fat_12: '971',
            fat_13: '347',
            fat_14: '41',
            fat_15: '38',
            fat_16: '168',
            fat_17: '6955'
          },
          node: {
            nd_0: '168',
            nd_1: '334',
            nd_2: '365',
            nd_3: '424',
            nd_4: '309',
            nd_5: '235',
            nd_6: '157',
            nd_7: '362',
            nd_8: '295',
            nd_9: '191',
            nd_10: '495',
            nd_11: '135'
          }
        },
        process_three: {
          task: {
            sc_1: '300',
            sc_2: '310',
            sc_3: '99',
            sc_4: '110',
            sc_5: '105',
            sc_6: '99',
            sc_7: '135',
            sc_8: '150',
            sc_9: '102',
            sc_10: '110',
            sc_11: '89',
            sc_12: '90',
            // 长度超过int，需吴博修改jar包，目前去掉四位
            // sc_3: '2312615216741',
            // sc_4: '2312615216741',
            // sc_5: '2312615216741',
            // sc_6: '2312615216741',
            // sc_7: '2312615216741',
            // sc_8: '781952857160',
            // sc_9: '781952857160',
            // sc_10: '781952857160',
            // sc_11: '781952857160',
            // sc_12: '781952857160',
            sc_13: '89',
            sc_14: '90',
            sc_15: '68',
            sc_16: '55',
            sc_17: '67',
            sc_18: '88',
            sc_19: '99',
            sc_20: '99',
            sc_21: '106',
            sc_22: '99',
            sc_23: '118',
            sc_24: '90',
            sc_25: '135',
            sc_26: '103',
            sc_27: '103',
            sc_28: '120',
            sc_29: '99',
            sc_30: '76',
            sc_31: '129',
            sc_32: '110',
            sc_33: '98',
            sc_34: '77'
          },
          node: {
            nd_0: '253',
            nd_1: '327',
            nd_2: '410',
            nd_3: '165',
            nd_4: '220',
            nd_5: '392',
            nd_6: '154',
            nd_7: '487',
            nd_8: '371',
            nd_9: '204',
            nd_10: '119',
            nd_11: '382',
            nd_12: '479',
            nd_13: '142',
            nd_14: '316',
            nd_15: '463',
            nd_16: '145',
            nd_17: '196',
            nd_18: '436',
            nd_19: '347',
            nd_20: '363'
          }
        }
      },
      processMap: {
        process_one: {
          '0': 'LoadVideo',
          '1': 'Prompt words',
          '2': 'Negative Prompt word',
          '3': 'Batch Prompt Schedule',
          '4': 'Load Model',
          '5': 'Transcoding',
          '6': 'Apply Controlnet',
          '7': 'Examine & Verify',
          '8': 'Image Resize',
          '9': 'Empty Latent Image',
          '10': 'VAE Decode',
          '11': 'Save Image',
          '12': 'Video Combine'
        },
        process_two: {
          '0': 'Source',
          '1': 'Copy',
          '2': 'Title',
          '3': 'Detect(1)',
          '4': 'Detect(2)',
          '5': 'Detect(3)',
          '6': 'Feature merger',
          '7': 'Graph Splitte',
          '8': 'Classify(1)',
          '9': 'Classify(2)',
          '10': 'Reco.Merge',
          '11': 'Display'
        },
        process_three: {
          '0': 'Source',
          '1': 'Data Processing',
          '2': 'Feature Extraction',
          '3': 'Date Cleaning',
          '4': 'Data Transformation',
          '5': 'Data Standardization',
          '6': 'Data Splitting',
          '7': 'Feature Selection',
          '8': 'Feature Transformation',
          '9': 'Feature Transformation',
          '10': 'Feature Fusion',
          '11': 'Processed(1)',
          '12': 'Processed(2)',
          '13': 'Processed(3)',
          '14': 'Processed(4)',
          '15': 'Model Processed',
          '16': 'Datapre Processing',
          '17': 'Model Training',
          '18': 'Model Evaluation',
          '19': 'Result Analysis',
          '20': 'Display'
        }
      }
    }
  },
  methods: {
    showUploadDialog() {
      this.uploadDialogVisible = true;
    },
    handleFileUpload(file) {
      const reader = new FileReader();
      reader.onload = (e) => {
        this.xmlStrWithCustom  = e.target.result;
        this.generate23423();
        this.uploadDialogVisible = false;
      };
      reader.onerror = () => {
        this.$message.error('文件读取失败，请重试');
        this.uploadDialogVisible = false;
      };
      reader.readAsText(file);
      return false; // Prevent default upload behavior
    },
    handInput() {
      let xml = ''
      switch (this.radio) {
        case '视频业务工作流':
          xml = this.$refs.modal.createNewDiagram(this.process.process_one.task.vi_1, this.process.process_one.task.vi_2, this.process.process_one.task.vi_3,
            this.process.process_one.task.vi_4, this.process.process_one.task.vi_5, this.process.process_one.task.vi_6, this.process.process_one.task.vi_7, this.process.process_one.task.vi_8, this.process.process_one.task.vi_9
            , this.process.process_one.task.vi_10, this.process.process_one.task.vi_11, this.process.process_one.task.vi_12, this.process.process_one.task.vi_13
            , this.process.process_one.task.vi_14, this.process.process_one.task.vi_15)
          break
        case '公共安全监控与响应工作流':
          xml = this.$refs.modal.createNewDiagram2(this.process.process_two.task.fat_0, this.process.process_two.task.fat_1, this.process.process_two.task.fat_2, this.process.process_two.task.fat_3,
            this.process.process_two.task.fat_4, this.process.process_two.task.fat_5, this.process.process_two.task.fat_6, this.process.process_two.task.fat_7, this.process.process_two.task.fat_8,
            this.process.process_two.task.fat_9, this.process.process_two.task.fat_10, this.process.process_two.task.fat_11, this.process.process_two.task.fat_12, this.process.process_two.task.fat_13
            , this.process.process_two.task.fat_14, this.process.process_two.task.fat_15, this.process.process_two.task.fat_16, this.process.process_two.task.fat_17)
          break
        case '科学计算工作流':
          xml = this.$refs.modal.createNewDiagram3(this.process.process_three.task.sc_1, this.process.process_three.task.sc_2, this.process.process_three.task.sc_3,
            this.process.process_three.task.sc_4, this.process.process_three.task.sc_5, this.process.process_three.task.sc_6, this.process.process_three.task.sc_7, this.process.process_three.task.sc_8
            , this.process.process_three.task.sc_9, this.process.process_three.task.sc_10, this.process.process_three.task.sc_11, this.process.process_three.task.sc_12, this.process.process_three.task.sc_13
            , this.process.process_three.task.sc_14, this.process.process_three.task.sc_15, this.process.process_three.task.sc_16, this.process.process_three.task.sc_17, this.process.process_three.task.sc_18
            , this.process.process_three.task.sc_19, this.process.process_three.task.sc_20, this.process.process_three.task.sc_21, this.process.process_three.task.sc_22, this.process.process_three.task.sc_23
            , this.process.process_three.task.sc_24, this.process.process_three.task.sc_25, this.process.process_three.task.sc_26, this.process.process_three.task.sc_27, this.process.process_three.task.sc_28
            , this.process.process_three.task.sc_29, this.process.process_three.task.sc_30, this.process.process_three.task.sc_31, this.process.process_three.task.sc_32, this.process.process_three.task.sc_33
            , this.process.process_three.task.sc_34)
          break
        case '自定义工作流':
          // xmlStrWithCustom
          xml = this.$refs.modal.createNewDiagram4(this.xmlStrWithCustom)
          break
      }
      this.xmlStrWithValues = xml
    },
    generate23423(){
      this.$refs.modal.createNewDiagram4(this.xmlStrWithCustom)
    },
    downloadXML() {
      const blob = new Blob([newxx], { type: 'application/xml' });
      const link = document.createElement('a');
      link.href = URL.createObjectURL(blob);
      link.download = '自定义工作流样例.xml';
      link.click();
      URL.revokeObjectURL(link.href);
    },
    getXML() {
      return new Promise((resolve, reject) => {
        this.bpmnModeler.saveXML({ format: true }, (err, xml) => {
          err ? reject(err) : resolve(xml);
        });
      });
    },
    generate() {
      this.isLoading = true
      setTimeout(() => {
        this.handInput()
        switch (this.radio) {
          case '视频业务工作流':
            this.params.processMap = this.processMap.process_one
            this.generate1()
            break
          case '公共安全监控与响应工作流':
            this.params.processMap = this.processMap.process_two
            this.generate2()
            break
          case '科学计算工作流':
            this.params.processMap = this.processMap.process_three
            this.generate3()
            break
        }

        reportingProcess(this.params).then((data) => {
          this.flag = true
          this.$message({ type: 'success', message: '操作成功' })
          this.isLoading = false
        }).catch((error) => {
          console.log(error)
          this.isLoading = false
        })
      }, 1000)
    },
    generate1() {
      const pplinkData = []
      const info0 = [0, 1, parseInt(this.process.process_one.task.vi_1)]
      pplinkData.push(info0)
      const info1 = [0, 2, parseInt(this.process.process_one.task.vi_2)]
      pplinkData.push(info1)
      const info2 = [0, 3, parseInt(this.process.process_one.task.vi_3)]
      pplinkData.push(info2)
      const info3 = [0, 4, parseInt(this.process.process_one.task.vi_4)]
      pplinkData.push(info3)
      const info4 = [1, 7, parseInt(this.process.process_one.task.vi_5)]
      pplinkData.push(info4)
      const info5 = [2, 7, parseInt(this.process.process_one.task.vi_6)]
      pplinkData.push(info5)
      const info6 = [3, 7, parseInt(this.process.process_one.task.vi_7)]
      pplinkData.push(info6)
      const info7 = [7, 8, parseInt(this.process.process_one.task.vi_8)]
      pplinkData.push(info7)
      const info8 = [8, 9, parseInt(this.process.process_one.task.vi_9)]
      pplinkData.push(info8)
      const info9 = [9, 10, parseInt(this.process.process_one.task.vi_10)]
      pplinkData.push(info9)
      const info10 = [4, 5, parseInt(this.process.process_one.task.vi_11)]
      pplinkData.push(info10)
      const info11 = [5, 6, parseInt(this.process.process_one.task.vi_12)]
      pplinkData.push(info11)
      const info12 = [6, 10, parseInt(this.process.process_one.task.vi_13)]
      pplinkData.push(info12)
      const info13 = [10, 11, parseInt(this.process.process_one.task.vi_14)]
      pplinkData.push(info13)
      const info14 = [11, 12, parseInt(this.process.process_one.task.vi_15)]
      pplinkData.push(info14)
      this.params.reportJson = pplinkData
      this.params.processInfo = this.xmlStrWithValues
      // cpu信息
      const cpuData = []
      const le = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
      cpuData.push(le)
      const cp = [parseInt(this.process.process_one.node.nd_0), parseInt(this.process.process_one.node.nd_1),
        parseInt(this.process.process_one.node.nd_2), parseInt(this.process.process_one.node.nd_3),
        parseInt(this.process.process_one.node.nd_4), parseInt(this.process.process_one.node.nd_5),
        parseInt(this.process.process_one.node.nd_6), parseInt(this.process.process_one.node.nd_7),
        parseInt(this.process.process_one.node.nd_8), parseInt(this.process.process_one.node.nd_9),
        parseInt(this.process.process_one.node.nd_10), parseInt(this.process.process_one.node.nd_11),
        parseInt(this.process.process_one.node.nd_12)]
      cpuData.push(cp)
      this.params.cpuJson = cpuData
    },
    generate2() {
      const pplinkData = []
      const info0 = [0, 1, parseInt(this.process.process_two.task.fat_0)]
      pplinkData.push(info0)
      const info1 = [1, 2, parseInt(this.process.process_two.task.fat_1)]
      pplinkData.push(info1)
      const info2 = [2, 3, parseInt(this.process.process_two.task.fat_2)]
      pplinkData.push(info2)
      const info3 = [2, 4, parseInt(this.process.process_two.task.fat_3)]
      pplinkData.push(info3)
      const info4 = [2, 5, parseInt(this.process.process_two.task.fat_4)]
      pplinkData.push(info4)
      const info5 = [3, 6, parseInt(this.process.process_two.task.fat_5)]
      pplinkData.push(info5)
      const info6 = [4, 6, parseInt(this.process.process_two.task.fat_6)]
      pplinkData.push(info6)
      const info7 = [5, 6, parseInt(this.process.process_two.task.fat_7)]
      pplinkData.push(info7)
      const info8 = [6, 7, parseInt(this.process.process_two.task.fat_8)]
      pplinkData.push(info8)
      const info9 = [7, 8, parseInt(this.process.process_two.task.fat_9)]
      pplinkData.push(info9)
      const info10 = [7, 9, parseInt(this.process.process_two.task.fat_10)]
      pplinkData.push(info10)
      const info11 = [8, 10, parseInt(this.process.process_two.task.fat_11)]
      pplinkData.push(info11)
      const info12 = [9, 10, parseInt(this.process.process_two.task.fat_12)]
      pplinkData.push(info12)
      const info13 = [10, 11, parseInt(this.process.process_two.task.fat_13)]
      pplinkData.push(info13)
      const info14 = [1, 6, parseInt(this.process.process_two.task.fat_14)]
      pplinkData.push(info14)
      const info15 = [1, 11, parseInt(this.process.process_two.task.fat_15)]
      pplinkData.push(info15)
      const info16 = [7, 10, parseInt(this.process.process_two.task.fat_16)]
      pplinkData.push(info16)
      const info17 = [7, 10, parseInt(this.process.process_two.task.fat_17)]
      pplinkData.push(info17)
      this.params.reportJson = pplinkData
      this.params.processInfo = this.xmlStrWithValues
      // cpu信息
      const cpuData = []
      const le = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
      cpuData.push(le)
      const cp = [parseInt(this.process.process_two.node.nd_0), parseInt(this.process.process_two.node.nd_1),
        parseInt(this.process.process_two.node.nd_2), parseInt(this.process.process_two.node.nd_3),
        parseInt(this.process.process_two.node.nd_4), parseInt(this.process.process_two.node.nd_5),
        parseInt(this.process.process_two.node.nd_6), parseInt(this.process.process_two.node.nd_7),
        parseInt(this.process.process_two.node.nd_8), parseInt(this.process.process_two.node.nd_9),
        parseInt(this.process.process_two.node.nd_10), parseInt(this.process.process_two.node.nd_11)]
      cpuData.push(cp)
      this.params.cpuJson = cpuData
    },
    generate3() {
      const pplinkData = []
      const info0 = [0, 1, parseInt(this.process.process_three.task.sc_1)]
      pplinkData.push(info0)
      const info1 = [0, 2, parseInt(this.process.process_three.task.sc_2)]
      pplinkData.push(info1)
      const info2 = [1, 3, parseInt(this.process.process_three.task.sc_3)]
      pplinkData.push(info2)
      const info3 = [1, 4, parseInt(this.process.process_three.task.sc_4)]
      pplinkData.push(info3)
      const info4 = [1, 5, parseInt(this.process.process_three.task.sc_5)]
      pplinkData.push(info4)
      const info5 = [1, 6, parseInt(this.process.process_three.task.sc_6)]
      pplinkData.push(info5)
      const info7 = [2, 7, parseInt(this.process.process_three.task.sc_7)]
      pplinkData.push(info7)
      const info8 = [2, 8, parseInt(this.process.process_three.task.sc_8)]
      pplinkData.push(info8)
      const info9 = [2, 9, parseInt(this.process.process_three.task.sc_9)]
      pplinkData.push(info9)
      const info10 = [2, 10, parseInt(this.process.process_three.task.sc_10)]
      pplinkData.push(info10)
      const info11 = [3, 11, parseInt(this.process.process_three.task.sc_11)]
      pplinkData.push(info11)
      const info12 = [3, 15, parseInt(this.process.process_three.task.sc_12)]
      pplinkData.push(info12)
      const info13 = [4, 12, parseInt(this.process.process_three.task.sc_13)]
      pplinkData.push(info13)
      const info14 = [4, 15, parseInt(this.process.process_three.task.sc_14)]
      pplinkData.push(info14)
      const info15 = [5, 13, parseInt(this.process.process_three.task.sc_15)]
      pplinkData.push(info15)
      const info16 = [5, 15, parseInt(this.process.process_three.task.sc_16)]
      pplinkData.push(info16)
      const info17 = [6, 14, parseInt(this.process.process_three.task.sc_17)]
      pplinkData.push(info17)
      const info18 = [6, 15, parseInt(this.process.process_three.task.sc_18)]
      pplinkData.push(info18)
      const info19 = [7, 15, parseInt(this.process.process_three.task.sc_19)]
      pplinkData.push(info19)
      const info20 = [7, 16, parseInt(this.process.process_three.task.sc_20)]
      pplinkData.push(info20)
      const info21 = [8, 15, parseInt(this.process.process_three.task.sc_21)]
      pplinkData.push(info21)
      const info22 = [8, 17, parseInt(this.process.process_three.task.sc_22)]
      pplinkData.push(info22)
      const info23 = [9, 15, parseInt(this.process.process_three.task.sc_23)]
      pplinkData.push(info23)
      const info24 = [9, 18, parseInt(this.process.process_three.task.sc_24)]
      pplinkData.push(info24)
      const info25 = [10, 15, parseInt(this.process.process_three.task.sc_25)]
      pplinkData.push(info25)
      const info26 = [10, 19, parseInt(this.process.process_three.task.sc_26)]
      pplinkData.push(info26)
      const info27 = [11, 20, parseInt(this.process.process_three.task.sc_27)]
      pplinkData.push(info27)
      const info28 = [12, 20, parseInt(this.process.process_three.task.sc_28)]
      pplinkData.push(info28)
      const info29 = [13, 20, parseInt(this.process.process_three.task.sc_29)]
      pplinkData.push(info29)
      const info30 = [14, 20, parseInt(this.process.process_three.task.sc_30)]
      pplinkData.push(info30)
      const info31 = [16, 20, parseInt(this.process.process_three.task.sc_31)]
      pplinkData.push(info31)
      const info32 = [17, 20, parseInt(this.process.process_three.task.sc_32)]
      pplinkData.push(info32)
      const info33 = [18, 20, parseInt(this.process.process_three.task.sc_33)]
      pplinkData.push(info33)
      const info34 = [19, 20, parseInt(this.process.process_three.task.sc_34)]
      pplinkData.push(info34)
      this.params.reportJson = pplinkData
      this.params.processInfo = this.xmlStrWithValues
      // cpu信息
      const cpuData = []
      const le = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
      cpuData.push(le)
      const cp = [parseInt(this.process.process_three.node.nd_0), parseInt(this.process.process_three.node.nd_1),
        parseInt(this.process.process_three.node.nd_2), parseInt(this.process.process_three.node.nd_3),
        parseInt(this.process.process_three.node.nd_4), parseInt(this.process.process_three.node.nd_5),
        parseInt(this.process.process_three.node.nd_6), parseInt(this.process.process_three.node.nd_7),
        parseInt(this.process.process_three.node.nd_8), parseInt(this.process.process_three.node.nd_9),
        parseInt(this.process.process_three.node.nd_10), parseInt(this.process.process_three.node.nd_11),
        parseInt(this.process.process_three.node.nd_12), parseInt(this.process.process_three.node.nd_13),
        parseInt(this.process.process_three.node.nd_14), parseInt(this.process.process_three.node.nd_15),
        parseInt(this.process.process_three.node.nd_16), parseInt(this.process.process_three.node.nd_17),
        parseInt(this.process.process_three.node.nd_18), parseInt(this.process.process_three.node.nd_19),
        parseInt(this.process.process_three.node.nd_20)
      ]
      cpuData.push(cp)
      this.params.cpuJson = cpuData
    }
  }
}
